name: Release Main Docker

on:
  workflow_dispatch:
  repository_dispatch:
    types: 'release-main-docker'

jobs:
  publish:
    name: Build and Push Docker Images
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: |
          sudo apt-get install xmlstarlet
          echo "REL_VERSION=$(curl -s https://raw.githubusercontent.com/zaproxy/zap-admin/master/ZapVersions.xml | xmlstarlet sel -t -v //core/version)" >> $GITHUB_ENV
          echo "REL_DATE=$(date +%F)" >> $GITHUB_ENV
      -
        name: Login to DockerHub
        uses: docker/login-action@v1 
        with:
          username: zapbot
          password: ${{ secrets.ZAPBOT_DOCKER_TOKEN }}
      - 
        name: Build stable Docker image
        uses: docker/build-push-action@v2
        with:
          load: true
          context: docker
          file: docker/Dockerfile-stable
          tags: |
            owasp/zap2docker-stable:s${{ env.REL_DATE }}
            owasp/zap2docker-stable:${{ env.REL_VERSION }}
            owasp/zap2docker-stable:latest
          build-args: |
            WEBSWING_URL=${{ secrets.WEBSWING_URL }}
      - run: docker push owasp/zap2docker-stable:s${{ env.REL_DATE }}
      - run: docker push owasp/zap2docker-stable:${{ env.REL_VERSION }}
      - run: docker push owasp/zap2docker-stable:latest
      -
        name: Build bare Docker image
        uses: docker/build-push-action@v2
        with:
          load: true
          context: docker
          file: docker/Dockerfile-bare
          tags: |
            owasp/zap2docker-bare:b${{ env.REL_DATE }}
            owasp/zap2docker-bare:${{ env.REL_VERSION }}
            owasp/zap2docker-bare:latest
      - run: docker push owasp/zap2docker-bare:b${{ env.REL_DATE }}
      - run: docker push owasp/zap2docker-bare:${{ env.REL_VERSION }}
      - run: docker push owasp/zap2docker-bare:latest
